package cn.xfdzx.android.apps.shop.presenter;

import org.json.JSONObject;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.AddAddressBeen;
import cn.xfdzx.android.apps.shop.bean.ProcurementTypeListBeen;
import cn.xfdzx.android.apps.shop.bean.ProcurementTypeSubmitBeen;
import cn.xfdzx.android.apps.shop.bean.PurchaseSubmitBeen;
import cn.xfdzx.android.apps.shop.contract.AddAddressContract;
import cn.xfdzx.android.apps.shop.contract.ProcurementTypeListContract;
import cn.xfdzx.android.apps.shop.model.AddAddressModel;
import cn.xfdzx.android.apps.shop.model.ProcurementTypeListModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author azheng
 * @date 2018/6/4.
 * Description：
 */
public class ProcurementTypeListPresenter extends BasePresenter<ProcurementTypeListContract.View> implements ProcurementTypeListContract.Presenter {

    private ProcurementTypeListContract.Model model;

    public ProcurementTypeListPresenter() {
        model = new ProcurementTypeListModel();
    }



    @Override
    public void procurementTypeList() {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.procurementTypeList()
                .compose(RxScheduler.<ProcurementTypeListBeen>Flo_io_main())
                .as(mView.<ProcurementTypeListBeen>bindAutoDispose())
                .subscribe(new Consumer<ProcurementTypeListBeen>() {
                    @Override
                    public void accept(ProcurementTypeListBeen bean) throws Exception {
                        mView.onProcurementTypeListSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void purchaseSubmit(ProcurementTypeSubmitBeen   body) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.purchaseSubmit(body)
                .compose(RxScheduler.<PurchaseSubmitBeen>Flo_io_main())
                .as(mView.<PurchaseSubmitBeen>bindAutoDispose())
                .subscribe(new Consumer<PurchaseSubmitBeen>() {
                    @Override
                    public void accept(PurchaseSubmitBeen bean) throws Exception {
                        mView.onPurchaseSubmitSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
}
